﻿//获取活动列表
var usercount = 1;
function getUsers(index, cateid) {

    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "1500", "pageIndex": index, "cateid": cateid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {

                usercount = data.count;
                var con = '';
                for (var i = 0; i < data.list.length; i++) {
                    var isJoinStr = '';
                    if (data.list[i].IsState == -1) { isJoinStr = "<input class=\"ybm\" id=\"act_join\" type=\"button\" value=\"已结束\">"; } else {
                        if (data.list[i].IsJoin == 0) { isJoinStr = "<input class=\"ybm\" id=\"act_join\" type=\"button\" value=\"已报名\">"; } else { isJoinStr = "<input class=\"bm\" id=\"act_join\" onclick=\"apply_join('" + data.list[i].Guid + "',1)\" type=\"button\" value=\"报名\">"; }
                    }
                    con += " <div class=\"hd_box\"><a href=\"m_activePage.html?proid=" + data.list[i].Guid + "\"><img alt=\"活动\" src=\"" + data.list[i].ImgUrl + "\"><p class=\"p_title\"><span><a href=\"m_activePage.html?proid=" + data.list[i].Guid + "\">" + data.list[i].Title + "</a></span></p><ul class=\"ul_box\"><li>时间：" + data.list[i].ActTime + "</li><li>地点：" + data.list[i].ActPlace + "</li><li>限额: " + data.list[i].ActCount + " 人</li><li class=\"p_ybm\"><span>已报名：</span>&nbsp;<span>" + data.list[i].ActJoinCount + "人</span></li></ul></a>" + isJoinStr + "</div>";

                }
                $("#m_indexCount").val(usercount);
                $("#zs_user").html(con);
            } else { alert(data.msg); }
        }
    });

}

//报名加入
function apply_join(proid, cateid) {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 1140, "proid": proid, "cateid": cateid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var joinBtnStr = '';

                switch (data.isLogin) {
                    case '0': alert('请先登录！'); GetLinkUrl("m_login.html"); break;
                        //case '2': alert('请补全详细资料'); GetLinkUrl("personerInfo.html"); break;
                    case '1': alert(data.msg); GetLinkUrl(data.url); $("#act_join").val("已报名"); break;
                    case '-1': alert('已经加入！'); break;
                }

            }
        }
    });
}

//获取活动详情
function getNewsInfo() {
    var proid = $.query.get("proid");
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "152", "proid": proid, "cateid": 1 },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $("#n_title").html(data.info.Title);
                //$("#n_time").html(data.info.TimeDate);
                //$("#n_sources").html("来源: " + data.info.Sources);
                $("#n_desc").html(data.info.Descriptions);
                $("#n_img").attr("src", data.info.ImgUrl);
                $("#n_actTime").html("时间：" + data.info.ActTime);
                $("#n_actPlace").html("地点：" + data.info.ActPlace);
                $("#n_actCompany").html("主办方：" + data.info.ActCompany);
                $("#n_acttBbudget").html("报名费：" + data.info.ActBbudget + " 元/人");
                $("#n_actCount").html("限额：" + data.info.ActCount + " 人");

                $("#n_actJoinCount").html(data.info.ActJoinCount + " 人");
                //$("#n_sources2").html("来源: " + data.info.Sources);
                //$("#n_author").html("作者: " + data.info.Author);
                //$("#n_editer").html("编辑: " + data.info.Editer);

                $("#act_top_title").html(data.info.Title);

                var isJoinStr = '';  var isPayStr = '';
                if (data.info.IsState == -1) { isJoinStr = ' <input class="btn_bm" type="button" value="已结束">'; } else {
                    if (data.isJoin == 1) { isJoinStr = ' <input class="btn_bm" type="button" value="已报名">'; if (data.isPay == 0) { $("#pro_pay").html("<input class=\"btn_ljzf\" type=\"button\" onclick=\"Get_act_pay('" + proid + "')\" value=\"立即支付\">"); } else { $("#pro_pay").html("<input class=\"btn_ljzf\"  type=\"button\"  value=\"已支付\">"); } } else { isJoinStr = " <input class=\"btn_bm\" type=\"button\" onclick=\"apply_join('" + data.info.Guid + "',2)\" value=\"报名\">"; }

                   
                     
                }

                $("#act_isJoin").html(isJoinStr);
            } else { alert(data.msg); }
        }
    });

}
function Get_act_pay(payStr)
{
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "164 ", "proid": payStr, "cateid": 2 },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                window.location.href = data.url;
            }
        }
    });
}


//获取我参加的活动列表

function getMyAct(index, cateid) {

    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "1501", "pageIndex": index, "cateid": cateid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {

                usercount = data.count;
                var con = ''; var join = '';
                for (var i = 0; i < data.list.length; i++) {
                    join = '';
                    if (GetSignTime(data.list[i].ActStartTime) == true) {
                    if (data.list[i].IsState == 1) {
                        if (data.list[i].IsJoin == 0) { join = "<input type=\"button\" value=\"签到\" onclick=\"GetActSign('" + data.list[i].Guid + "')\" class=\"btn_qdL\">"; } else { join = "<input type=\"button\" value=\"已签到\" class=\"btn_qdH\">"; }
                    }}
                    con += "<div class=\"hd_box\"><a href=\"m_activePage.html?proid=" + data.list[i].Guid + "\"><img alt=\"活动\" src=\"" + data.list[i].ImgUrl + "\"></a><p class=\"p_title\"><span><a href=\"m_activePage.html?proid=" + data.list[i].Guid + "\" style='color:#666;'>" + data.list[i].Title + "</a></span></p><ul class=\"ul_box\"><li>时间：" + data.list[i].ActTime + "</li><li>地点：" + data.list[i].ActPlace + "</li><li>限额：" + data.list[i].ActCount + " 名</li><li class=\"p_ybm\"><span>已报名：</span>&nbsp;<span>" + data.list[i].ActJoinCount + "人</span></li></ul>" + join + "</div>";

                }
                $("#m_indexCount").val(usercount);
                $("#zs_user").html(con);
            } else { alert(data.msg); }
        }
    });

}



//计算时间大小
function GetSignTime(startdate) {

 
    var starttime = GetFormatDate(startdate);
   
    var enddate = new Date();
    enddate = GetFormatDate(enddate);
 
    if (enddate == starttime) {
        return true;
    }
    else
        return false;

}


function GetFormatDate(date_str) {
    var date = new Date(date_str);
    var dStr = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    return dStr;
}

function GetActSign(actStr)
{
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "153 ", "proid": actStr },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                alert("签到成功");
                $(".btn_qdL").attr("class", "btn_qdH").unbind("click");
            }
        }
    });
}
function GetLinkUrl(url) { window.location.href = url; }

function GetUser_Info()//用户信息
{
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "106" },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $("#my_data_imgurl").attr("src", data.img);
                $("#my_data_name").html(data.name);
                //$("#my_data_point").html(data.point);
            }
        }
    });
}



//获取项目人员列表
function getItemUsers(index, cateid) {
    var proid = $.query.get("proid");
    if (proid != "") {
        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "1260", "pageIndex": index, "cateid": cateid, "proid": proid },
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {

                    usercount = data.count;
                    var item = ''; var userState = ''; var item_url = '';
                    for (var i = 0; i < data.list.length; i++) {

                        if (data.list[i].IsState == 1) { userState = "<a href=\"javascript:void(0)\" style=\"color: #26BCD5;\"> 已通过</a>"; } else { userState = "<a href=\"javascript:void(0)\" onclick=\"GetAgreeApply('" + proid + "','" + data.list[i].UserGuid + "',this)\" style=\"color: #26BCD5;\"> 通过</a>"; }
                        item_url = "talentPage.html?proid=" + data.list[i].Guid;
                        item += "<div class=\"chaBox\"><div class=\"img_le\" style=\"background: url(" + data.list[i].ImgUrl + ") no-repeat center;background-size: 100%;\"></div> <div class=\"content_txt\"><p><span>" + data.list[i].UNickName + "：" + data.list[i].UMajor + "</span><span class=\"span_type\">" + userState + "</span></p><p><span>成就：" + data.list[i].UHarvest + "</span></p></div></div>";

                    }
                    $("#apply_user").html(item);  //项目  
                } else { alert(data.msg); }
            }
        });
    }

}
function GetAgreeApply(proid, idStr, id) {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "1261", "idStr": idStr, "proid": proid },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $(id).text("已通过");
            }
        }
    });
}